home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / libs / MMULib.lha / MMULib / Lib_Sources / mu_detect.a < prev    next >
Encoding:
Text File  |  1998-10-04  |  9.2 KB  |  246 lines

  1. ;*************************************************************************
  2. ;** mmu.library                                                         **
  3. ;**                                                                     **
  4. ;** a system library for arbitration and control of the MC68K MMUs      **
  5. ;**                                                                     **
  6. ;** © 1998 THOR-Software, Thomas Richter                                **
  7. ;** No commercial use, reassembly, modification without prior, written  **
  8. ;** permission of the authors.                                          **
  9. ;** Including this library in any commercial software REQUIRES a        **
  10. ;** written permission and the payment of a small fee.                  **
  11. ;**                                                                     **
  12. ;** This is an internal header file, do not depend on anything here.    **
  13. ;** Use the official include files.                                     **
  14. ;** Distributed only for the mmu.library development group for private  **
  15. ;** use.                                                                **
  16. ;**                                                                     **
  17. ;**---------------------------------------------------------------------**
  18. ;** Block: Detect.a                                                     **
  19. ;** Detect a possible MMU, return the type in d0                        **
  20. ;** Version 0.01                15.09.1998              © THOR          **
  21. ;*************************************************************************
  22.  
  23. ;FOLD Includes
  24.         include INC:exec_lib.asm
  25.         include mu_lib.i
  26. ;ENDFOLD
  27. ;FOLD Externals
  28.         xref SubSuper
  29. ;ENDFOLD
  30.  
  31.         section main_code,code
  32.  
  33. ;FOLD DetectMMUType
  34. ;*************************************************
  35. ;** DetectMMUType                               **
  36. ;** Return the type of the MMU installed        **
  37. ;** this does NOT YET check whether an EC type  **
  38. ;** processor is installed, this must be done   **
  39. ;** manually afterwards. It checks only the     **
  40. ;** possible type of the MMU                    **
  41. ;*************************************************
  42.         xdef DetectMMUType
  43. DetectMMUType:
  44.         move.b mulib_AttnFlags(a6),d1           ;get CPU type
  45.  
  46.         btst #AF_68060,d1
  47.         bne.s .found060
  48.         tst.l mulib_060Base(a6)
  49.         bne.s .found060lib
  50.  
  51.         btst #AF_68040,d1
  52.         bne.s .found040
  53.  
  54.         moveq #mutype_none,d0
  55.         btst #AF_68020,d1                       ;not even a '020?
  56.         beq.s .found                            ;if so, exit
  57.  
  58.                                                 ;check here whether MMU is available
  59.         pea Check020MMU(pc)
  60.         bsr SubSuper                            ;run this
  61.         tst.l d0                                ;what is it?
  62.         beq.s .found                            ;nothing ?
  63.  
  64.         moveq #mutype_68030,d0
  65.         btst #AF_68030,mulib_AttnFlags(a6)      ;is the '030 installed ?
  66.         bne.s .found
  67.  
  68.         moveq #mutype_68851,d0
  69.         bra.s .found
  70. .found060lib:
  71.         pea Check060MMU(pc)
  72.         bsr SubSuper
  73.         tst.l d0
  74.         beq.s .found040
  75. .found060:
  76.         bset #AF_68060,mulib_AttnFlags(a6)
  77.         pea Check060MMU(pc)
  78.         bsr SubSuper
  79.         tst.l d0
  80.         beq.s .found
  81.  
  82.         moveq #mutype_68060,d0
  83.         bra.s .found
  84. .found040:
  85.         bset #AF_68040,mulib_AttnFlags(a6)
  86.         pea Check040MMU(pc)
  87.         bsr SubSuper
  88.         tst.l d0
  89.         beq.s .found
  90.  
  91.         moveq #mutype_68040,d0
  92. .found:
  93.         rts
  94. ;ENDFOLD
  95. ;FOLD Check020MMU
  96. ;*************************************************
  97. ;** Check020MMU                                 **
  98. ;** Check, whether a 68851 is on board          **
  99. ;*************************************************
  100.  
  101.         machine mc68020
  102.         pmmu
  103.  
  104. Check020MMU:
  105.         ori.w #$0700,sr                 ;disable interrupts
  106.         lea -$e4(a7),a7                 ;reserve room for termporary
  107.                                         ;exception vectors
  108.         movec.l vbr,a0                  ;saveback VBR
  109.         lea .illegal(pc),a1             ;entry for Illegal/LineF
  110.         move.l a1,$10(a7)               ;set it
  111.         move.l a1,$2c(a7)               ;ditto
  112.         lea .nmi(pc),a1
  113.         move.l a1,$7c(a7)               ;NMI disable
  114.         lea .config(pc),a1
  115.         move.l a1,$e0(a7)
  116.         movec.l a7,vbr                  ;VBR temporary on stack
  117.         clr.l 4(a7)                     ;clear this
  118.         moveq #1,d0                     ;default result is: YES
  119.         pmove tc,(a7)                   ;try to read translation control
  120.         pmove 4(a7),tc                  ;try to write it
  121.         pflusha                         ;this might generate an exception for the EC30
  122.         tst.l (a7)                      ;Enabled ?
  123.         bpl.s .continue                 ;continue if disabled
  124.         pmove (a7),tc                   ;is enabled. If so, must be valid
  125. .continue:
  126.         movec.l a0,vbr                  ;restore VBR
  127.                                         ;result is in d0
  128.         lea $e4(a7),a7                  ;release stack
  129. .nmi:
  130.         rte                             ;this restores interrupts anyways
  131. .illegal:
  132.         moveq #0,d0
  133.         addq.l #8,a7                    ;remove exception stack frame
  134.         bra.s .continue
  135. .config:
  136.         moveq #0,d0
  137.         addq.l #8,a7
  138.         addq.l #4,a7
  139.         bra.s .continue                 ;MMU configuration error
  140. ;ENDFOLD
  141. ;FOLD Check040MMU
  142. ;*************************************************
  143. ;** Check040MMU                                 **
  144. ;** Check, whether a 68040 MMU is on board      **
  145. ;*************************************************
  146.  
  147.         machine mc68040
  148.  
  149. Check040MMU:
  150.         ori.w #$0700,sr                 ;disable interrupts
  151.         lea -$80(a7),a7                 ;reserve room for termporary
  152.                                         ;exception vectors
  153.         movec.l vbr,a0                  ;saveback VBR
  154.         lea .illegal(pc),a1             ;entry for Illegal/LineF
  155.         move.l a1,$10(a7)               ;set it
  156.         move.l a1,$2c(a7)               ;ditto
  157.         lea .nmi(pc),a1
  158.         move.l a1,$7c(a7)               ;NMI disable
  159.         movec.l a7,vbr                  ;VBR temporary on stack
  160.         moveq #1,d0                     ;default result is: YES
  161.         moveq #0,d1
  162.         sub.l a1,a1
  163.         movec.l tc,d1                   ;try to read translation control
  164.         pflusha                         ;this generates an exception for the EC40
  165.         movec.l a1,tc                   ;try to clear it
  166.         tst.w d1                        ;enabled ?
  167.         bpl.s .continue
  168.         movec.l d1,tc                   ;if enabled, write back
  169. .continue:
  170.         movec.l a0,vbr                  ;restore VBR
  171.                                         ;result is in d0
  172.         lea $80(a7),a7                  ;release stack
  173. .nmi:
  174.         rte                             ;this restores interrupts anyways
  175. .illegal:
  176.         moveq #0,d0
  177.         addq.l #8,a7                    ;remove exception stack frame
  178.         bra.s .continue
  179. ;ENDFOLD
  180. ;FOLD Check060MMU
  181. ;*************************************************
  182. ;** Check060MMU                                 **
  183. ;** Check, whether a 68060 MMU is on board      **
  184. ;*************************************************
  185.  
  186.         machine mc68060
  187.  
  188. Check060MMU:
  189.         ori.w #$0700,sr                 ;disable interrupts
  190.         lea -$80(a7),a7                 ;reserve room for termporary
  191.                                         ;exception vectors
  192.         movec.l vbr,a0                  ;saveback VBR
  193.         lea .illegal(pc),a1             ;entry for Illegal/LineF
  194.         move.l a1,$10(a7)               ;set it
  195.         move.l a1,$2c(a7)               ;ditto
  196.         lea .nmi(pc),a1
  197.         move.l a1,$7c(a7)               ;NMI disable
  198.         movec.l a7,vbr                  ;VBR temporary on stack
  199.         moveq #0,d0
  200.         movec.l pcr,d1
  201.         swap d1
  202.         cmp.w #%0000010000110000,d1
  203.         bne.s .continue
  204.         moveq #1,d0                     ;default result is: YES
  205.         moveq #0,d1
  206.         sub.l a1,a1
  207.         movec.l tc,d1                   ;try to read translation control
  208.         movec.l a1,tc                   ;try to clear it
  209.         tst.w d1                        ;enabled ?
  210.         bpl.s .continue
  211.         movec.l d1,tc                   ;if enabled, write back
  212. .continue:
  213.         movec.l a0,vbr                  ;restore VBR
  214.                                         ;result is in d0
  215.         lea $80(a7),a7                  ;release stack
  216. .nmi:
  217.         rte                             ;this restores interrupts anyways
  218. .illegal:
  219.         moveq #0,d0
  220.         addq.l #8,a7                    ;remove exception stack frame
  221.         bra.s .continue
  222. ;ENDFOLD
  223. ;FOLD ReadVBR
  224. ;*************************************************
  225. ;** ReadVBR                                     **
  226. ;** read the vector base register -> a0         **
  227. ;** this is not necessarely fast, but executes  **
  228. ;** fine in user mode                           **
  229. ;*************************************************
  230.         machine mc68010
  231.  
  232.         xdef ReadVBR
  233. ReadVBR:
  234.         sub.l a0,a0
  235.         btst #AF_68010,mulib_AttnFlags(a6)      ;only 68010 and up
  236.         beq.s .exit
  237.         pea _ReadVBR(pc)
  238.         bsr SubSuper
  239. .exit:
  240.         rts
  241. _ReadVBR:
  242.         movec.l vbr,a0
  243.         rte
  244. ;ENDFOLD
  245.  
  246.